<?php
require 'emos/init.php';

use Emos\Form;
use Emos\Db;
use Emos\Editor;



$db = new Db\MySql;
$db->connect(array('base'=>'emos'));

$form = new Form\Form();

$ent = new Editor\Entity('field_type', 'id');
$ent->db = $db;
$ent->form = $form;
//$ent->render();


$setA = new Form\ExpandableSet();
$setA->add('aaa', 'AAA', new Form\Text());
$setA->add('bbb', 'BBB', new Form\Textarea());

$setB = new Form\ItemSet();
$setB->add('ddd', 'ddd', new Form\Text());
$setB->add('ccc', 'ccc', new Form\Text());

$setC = new Form\ItemSet();
$setC->add('eee', 'eee', new Form\Text());
$setC->add('fff', 'fff', new Form\Text());


$setN = new Form\ExpandableSet();
$setN->add('nnn', 'NNN', new Form\Textarea());
$setC->add(null, null, $setN);

$tabSet = new Form\TabSet();
$tabSet->addTab('Tab B', $setB);
$tabSet->addTab('Tab C', $setC);


$form->elementSet->add('text',       'Text',     new Form\Text());
$form->elementSet->add('text2',       'Text',     new Form\Text());
$form->elementSet->add('textarea',    'Textarea',  new Form\Textarea());
$form->elementSet->add('checkbox',     'checkbox',   new Form\Checkbox())->setValues('no','yes')->setRemark('Check me!');
$form->elementSet->add('_cont',      null,       new Form\Separator('Contacts'));


$form->elementSet->add('latlng',     'Coordinates',     new Form\LatLng());

/*
$form->elementSet->add('_setA', null, $setA);
$form->elementSet->add('_tabs', null, $tabSet);
*/

//$form->init();

//$form->setValuesFromRecord(array('name'=>'Andrey Tushev', 'active'=>'yes', 'coords_lat'=>12.123456789, 'coords_lng'=>34.123456789));
//$form->setValuesFromRecord($db->selectRow("SELECT * FROM field_type WHERE id = ?id:int", array('id'=>(int)@$_GET['id'])));

/*
print $form->getHtml();

if(count($_POST)>0) {    
    print"<pre>INSERT: ". $form->insert()."</pre>";
}

print"<pre>";print_r($ent->getDdl());print"</pre>";


?>
<div class="emos">emos</div>
<?
*/

$tree = new Editor\TreeAdmin();
$tree->setDb($db);
$tree->addEntity($ent);
$tree->init();
$tree->ajax();



